package com.itheima.test_demo;

import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileOutputStream;

public class test {
    public static void main(String[] args) throws Exception {
        //在内存中创建一个Excel文件
        XSSFWorkbook workbook = new XSSFWorkbook();
//创建工作表，指定工作表名称
        XSSFSheet sheet = workbook.createSheet("传智播客");

//创建行，0表示第一行
        XSSFRow row = sheet.createRow(0);
//创建单元格，0表示第一个单元格
        row.createCell(0).setCellValue("编号");
        row.createCell(1).setCellValue("名称");
        row.createCell(2).setCellValue("年龄");

        XSSFRow row1 = sheet.createRow(1);
        row1.createCell(0).setCellValue("1");
        row1.createCell(1).setCellValue("小明");
        row1.createCell(2).setCellValue("10");

        XSSFRow row2 = sheet.createRow(2);
        row2.createCell(0).setCellValue("2");
        row2.createCell(1).setCellValue("小王");
        row2.createCell(2).setCellValue("20");

        //通过输出流将workbook对象输出到磁盘
        FileOutputStream out = new FileOutputStream("D:\\itcast.xlsx");
        workbook.write(out);
        out.flush();//清空缓冲区
        out.close();
        workbook.close();

    }
}
